#!/usr/bin/python3.7
import sys
import argparse
import json
import csv



out_file=open("./transit/NVDCVE.csv","a")


with open(sys.argv[1], 'rb') as input_file:
	cvestr=json.load(input_file)
	for cve in cvestr['CVE_Items']:

		cve_id = cve['cve']['CVE_data_meta']['ID']
		# print (cve_id)

		if 'baseMetricV3' in cve['impact']:
			scope = cve['impact']['baseMetricV3']['cvssV3']['scope']
			score = cve['impact']['baseMetricV3']['cvssV3']['baseScore']
			cvss = 3
		elif 'baseMetricV2' in cve['impact']:
			scope = "unknown"
			score = cve['impact']['baseMetricV2']['cvssV2']['baseScore']
			cvss = 2
		else:
			scope = "unknown"
			score = 0
			cvss = 0
		
		row=[cve_id,cvss,score,scope]
		writer = csv.writer(out_file)
		writer.writerows([row])

input_file.close()
out_file.close()
